using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using LuDC.CKEditor.Models;

namespace LuDC.CKEditor
{
	public class Migrations : DataMigrationImpl
	{
		public int Create()
		{
			// Creating table CKEditorSettingsPartRecord
			SchemaBuilder.CreateTable("CKEditorSettingsPartRecord", table => table
				.ContentPartRecord()
				.Column<string>("ContentsCss", c => c.WithDefault(CKEditorSettingsPartRecord.DefaultContentsCss).WithLength(255))
				.Column<string>("ExtraPlugins", c => c.WithDefault(CKEditorSettingsPartRecord.DefaultExtraPlugins).WithLength(1024))
				.Column<bool>("ClearDefaultStyleSets", c => c.NotNull().WithDefault(CKEditorSettingsPartRecord.DefaultClearDefaultStyleSets))
				.Column<bool>("EnableAdvancedContentFilter", c => c.NotNull().WithDefault(CKEditorSettingsPartRecord.DefaultEnableAdvancedContentFilter))
				.Column<string>("Toolbar", column => column.Unlimited().WithDefault(CKEditorSettingsPartRecord.DefaultToolbar))
			);

			return 2;
		}

		public int UpdateFrom1()
		{
			SchemaBuilder.DropTable("CKEditorSettingsPartRecord");

			SchemaBuilder.CreateTable("CKEditorSettingsPartRecord", table => table
				.ContentPartRecord()
				.Column<string>("ContentsCss", c => c.WithDefault(CKEditorSettingsPartRecord.DefaultContentsCss).WithLength(255))
				.Column<string>("ExtraPlugins", c => c.WithDefault(CKEditorSettingsPartRecord.DefaultExtraPlugins).WithLength(1024))
				.Column<bool>("ClearDefaultStyleSets", c => c.NotNull().WithDefault(CKEditorSettingsPartRecord.DefaultClearDefaultStyleSets))
				.Column<bool>("EnableAdvancedContentFilter", c => c.NotNull().WithDefault(CKEditorSettingsPartRecord.DefaultEnableAdvancedContentFilter))
				.Column<string>("Toolbar", column => column.Unlimited().WithDefault(CKEditorSettingsPartRecord.DefaultToolbar))
			);

			return 2;
		}
	}
}